/**
 * 
 */
package it.irondev.appturismo.util;

import it.irondev.appturismo.service.ICityService;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 * @author federico
 *
 */
@Component
public class CityInterceptor implements Interceptor {

	/**
	 * 
	 * 
	 */
	@Autowired
	ICityService cityService;
	
	private static final long serialVersionUID = -5731338247758861970L;

	public void destroy() {
		
	}

	public void init() {
		
	}

	public String intercept(ActionInvocation actionInvocation) throws Exception {
		
		Map<String,Object> params = actionInvocation.getInvocationContext().getParameters();
		Map<String, Object> session = actionInvocation.getInvocationContext().getSession();
		if(params.containsKey("city")) {
			String[] city = (String[]) params.get("city");
			session.put("mapp-city", Integer.parseInt(city[0]));
		}
		String result = actionInvocation.invoke();
		return result;
	}

}
